package com.rc.saas.tenant.service.tenant;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.mapper.tenant.TenantManufacturerMapper;
import com.rc.saas.tenant.model.tenant.TenantManufacturer;
import com.rc.saas.tenant.model.tenant.TenantManufacturerExample;
import com.rc.saas.tenant.base.BaseSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author frog
 * @date 2019/12/3
 */
@Service
public class TenantManufacturerServiceImpl implements TenantManufacturerService {

    @Autowired
    private TenantManufacturerMapper tenantManufacturerMapper;

    @Override
    public TenantManufacturerMapper getMapper() {
        return tenantManufacturerMapper;
    }

    @Override
    public PageInfo<TenantManufacturer> searchByCondition(BaseSearch baseSearch) {
        PageHelper.startPage(baseSearch.getOffset(), baseSearch.getLimit());
        TenantManufacturerExample example = new TenantManufacturerExample();
        example.createCriteria().andTenantCodeEqualTo(baseSearch.getTenantCode());
        List<TenantManufacturer> tenantManufacturers = tenantManufacturerMapper.selectByExample(example);
        return new PageInfo<TenantManufacturer>(tenantManufacturers);
    }

    /*
    * type 查询类型 0:桩，枪 1：桩 2：枪
    * */
    @Override
    public List<TenantManufacturer> selectByTenantCode(String tenantCode,String type) {
        TenantManufacturerExample example = new TenantManufacturerExample();
        //ManufacturerType  0:桩 枪1:桩2:枪

        List<String> pileList = new ArrayList <>();
        pileList.add("0");
        if ("1".equals(type)){
            pileList.add("1");
        }else if ("2".equals(type)){
            pileList.add("2");
        }else {
            pileList.add("1");
            pileList.add("2");
        }
        //状态 0:正常 1:暂停 默认0
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andManufacturerTypeIn(pileList).andStatusEqualTo("0");
        List<TenantManufacturer> tenantManufacturerList = tenantManufacturerMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(tenantManufacturerList)) {
            return tenantManufacturerList;
        }
        return null;
    }


}
